package com.shiguiwu.springmybatis.netty.http;

import com.shiguiwu.springmybatis.netty.http.handler.HttpServerHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;
import lombok.extern.slf4j.Slf4j;

/**
 * @description: 初始化器
 * 此类的作用是：向管道加入处理器
 * @author: stone
 * @date: Created by 2022/11/13 20:31
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.netty.http
 */
@Slf4j
public class HttpServerInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {

        //1，获取管道
        ChannelPipeline pipeline = socketChannel.pipeline();

        //2，添加http编解码器
        pipeline.addLast("myHttpServerCodec", new HttpServerCodec());

        //3，添加一个处理器
        pipeline.addLast("myHttpServerHandler", new HttpServerHandler());

        log.info("init 完成======>");

    }
}
